package com.kingyea.mobilepolice.apimanage.servicehistory.service.impl;

import com.kingyea.mobilepolice.apimanage.servicehistory.bean.ServiceHistory;
import com.kingyea.mobilepolice.apimanage.servicehistory.dao.ServiceHistoryMapper;
import com.kingyea.mobilepolice.apimanage.servicehistory.service.ServiceHistoryService;
import com.kingyea.mobilepolice.apimanage.utils.page.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description ServiceHistory 实现类
 * @date Created in 2018-05-05 17:51:23
 */
@Service
@Transactional
public class ServiceHistoryServiceImpl implements ServiceHistoryService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ServiceHistoryServiceImpl.class);

    @Resource
    private ServiceHistoryMapper serviceHistoryMapper;

    /**
     * 通过ID查找对象
     *
     * @param serviceSerialNo
     * @param version
     * @return
     */
    @Override
    public ServiceHistory getById(String serviceSerialNo, String version) throws Exception {
        return this.serviceHistoryMapper.getById(serviceSerialNo, version);
    }

    /**
     * 列表
     *
     * @param
     * @return
     */
    @Override
    public List<ServiceHistory> list(ServiceHistory serviceHistory) throws Exception {
        List<ServiceHistory> list = serviceHistoryMapper.list(serviceHistory);
        return list;
    }

    /**
     * 删除
     *
     * @param serviceSerialNo, version
     * @return
     */
    @Override
    public int deleteById(String serviceSerialNo, String version) throws Exception {
        serviceHistoryMapper.deleteById(serviceSerialNo, version);
        return 1;
    }

    /**
     * 保存
     *
     * @param serviceHistory
     * @return
     */
    @Override
    public ServiceHistory save(ServiceHistory serviceHistory) throws Exception {
        try {
            serviceHistoryMapper.save(serviceHistory);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return serviceHistory;
    }

    /**
     * 更新
     *
     * @param serviceHistory
     * @return
     */
    @Override
    public ServiceHistory update(ServiceHistory serviceHistory) throws Exception {
        try {
            serviceHistoryMapper.update(serviceHistory);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return serviceHistory;
    }

    @Override
    public PageInfo searchByCondition(Map<String, Object> map) throws Exception {
        PageInfo.startPage(map);
        return PageInfo.getPageInfo(serviceHistoryMapper.searchByCondition(map));
    }


}
